//
//  averageWidthCollectionViewController.m
//  CJUIKitDemo
//
//  Created by ciyouzen on 8/10/15.
//  Copyright (c) 2015 dvlproad. All rights reserved.
//

#import "TSExtralTagCollectionViewController.h"
#import <CQDemoKit/CQTSContainerViewFactory.h>
#import <CQDemoKit/CJUIKitRandomUtil.h>
#import <CQTagCollectionView/CQExtralTagSeletedCollectionView.h>

@interface TSExtralTagCollectionViewController () {
    
}
@property (nonatomic, strong) CQExtralTagSeletedCollectionView *collectionView;
@end

@implementation TSExtralTagCollectionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title = @"自定义标签页";
    
    
    
    // buttonsView
    UIView *buttonsView = [CQTSContainerViewFactory threeButtonsViewAlongAxis:MASAxisTypeVertical title1:@"CJExtralItemSettingNone" actionBlock1:^(UIButton * _Nonnull bButton) {
        [self extralItemSettingNone];
        
    } title2:@"CJExtralItemSettingLeading" actionBlock2:^(UIButton * _Nonnull bButton) {
        [self extralItemSettingLeading];
        
    } title3:@"CJExtralItemSettingTailing" actionBlock3:^(UIButton * _Nonnull bButton) {
        [self extralItemSettingTailing];
    }];
    [self.view addSubview:buttonsView];
    [buttonsView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).mas_offset(120);
        make.height.mas_equalTo(44*3+10*2);
        make.centerX.mas_equalTo(self.view);
        make.left.mas_equalTo(self.view).mas_offset(20);
    }];
    
    


    CGFloat leftRightInset = 36;
    CQExtralTagSeletedCollectionView *collectionView = [[CQExtralTagSeletedCollectionView alloc] initWithItemHorizontalSpacing:10 itemVerticalSpacing:16 sectionLeftRightInset:leftRightInset sectionSpacing:16 sectionSettingBlock:^CJDataSourceSettingModel * _Nonnull(NSInteger section) {
        if (section == 0) {
            return nil;
        } else {
            CJDataSourceSettingModel *dataSourceSettingModel = [[CJDataSourceSettingModel alloc] init];
            dataSourceSettingModel.maxDataModelShowCount = 1;
            dataSourceSettingModel.extralItemSetting = CJExtralItemSettingTailing;
            return dataSourceSettingModel;
        }
        
    } textFormatBlock:nil addTagBlock:^(CQExtralTagSeletedCollectionView * _Nonnull bCollectionView, NSIndexPath * _Nonnull indexPath) {
        NSString *text = @"某知名但不赚钱的互联网公司啊啊...";
        [bCollectionView addTagString:text indexPath:indexPath];
    } updateTagBlock:^(CQExtralTagSeletedCollectionView * _Nonnull bCollectionView, NSIndexPath * _Nonnull indexPath, NSString * _Nonnull oldTagString) {
        NSString *text = cqtsRandomString(1, 40, CQRipeStringTypeChinese);
        [bCollectionView updateTagString:text indexPath:indexPath];
    }];
    collectionView.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:collectionView];
    [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(buttonsView.mas_bottom).mas_offset(10);
        make.left.mas_equalTo(self.view).mas_offset(10);
        make.centerX.mas_equalTo(self.view);
        make.height.mas_equalTo(260);
    }];
    self.collectionView = collectionView;
    
    // 设置
    NSString *selectTagString = nil;
    
    NSArray *unableEditTagStrings1 = @[@"互联网", @"金融", @"咨询", @"政府机构", @"工业/制造", @"教育/科研",
                                      @"学生", @"影视/娱乐", @"医药健康", @"媒体公关", @"建筑/地产", @"服务业",
                                      @"文化/艺术", @"商业/零售", @"自由职业"
                                    ];
    NSArray *unableEditTagStrings2 = @[];
    [self.collectionView configUnableEditTagSectionStrings:@[unableEditTagStrings1, unableEditTagStrings2] defaultSelectTagString:selectTagString];
    [self.collectionView reloadData];
}

#pragma mark - SettingEvent
- (void)extralItemSettingNone {
    [self updateExtralItemSetting:CJExtralItemSettingNone];
}

- (void)extralItemSettingLeading {
    [self updateExtralItemSetting: CJExtralItemSettingLeading];
}

- (void)extralItemSettingTailing {
    [self updateExtralItemSetting: CJExtralItemSettingTailing];
}

/// 更新额外cell的样式即位置，(默认不添加）
- (void)updateExtralItemSetting:(CJExtralItemSetting)extralItemSetting {
    [self.collectionView updateSectionSettingBlock:^CJDataSourceSettingModel * _Nonnull(NSInteger section) {
        if (section == 0) {
            return nil;
        } else {
            CJDataSourceSettingModel *dataSourceSettingModel = [[CJDataSourceSettingModel alloc] init];
            dataSourceSettingModel.maxDataModelShowCount = 1;
            dataSourceSettingModel.extralItemSetting = extralItemSetting;
            return dataSourceSettingModel;
        }
    }];
    [self.collectionView reloadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
